package com.holic;

import java.util.List;

import com.holic.bean.Product;
import com.holic.db.ProductDao;
import com.holic.fetch.ListFetcher;

public class Crawler {
	
	private ListFetcher listFetcher = new ListFetcher();
	private ProductDao productDao = new ProductDao();
	private Thread thread = null;
	/**
	 * 开始抓取
	 */
	public void start(){
		thread = new Thread(){
			@Override
			public void run() {
				crawl();
			}
		};
		thread.setDaemon(true);
		thread.start();
	}
	
	private void crawl(){
		List<Product> products = listFetcher.fetch("001");
		try{
			productDao.insert(products);
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 停止抓取
	 */
	public void stop(){
		listFetcher.close();
	}
	
}
